package com.ruoyi.jhczb.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.jhczb.domain.JhcZb;
import com.ruoyi.jhczb.service.IJhcZbService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 进耗存录入总表Controller
 * 
 * @author lgx
 * @date 2022-11-17
 */
@RestController
@RequestMapping("/jhczb/zb")
public class JhcZbController extends BaseController
{
    @Autowired
    private IJhcZbService jhcZbService;

    /**
     * 查询进耗存录入总表列表
     */
    @PreAuthorize("@ss.hasPermi('jhczb:zb:list')")
    @GetMapping("/list")
    public TableDataInfo list(JhcZb jhcZb)
    {
        startPage();
        List<JhcZb> list = jhcZbService.selectJhcZbList(jhcZb);
        return getDataTable(list);
    }

    /**
     * 导出进耗存录入总表列表
     */
    @PreAuthorize("@ss.hasPermi('jhczb:zb:export')")
    @Log(title = "进耗存录入总表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JhcZb jhcZb)
    {
        List<JhcZb> list = jhcZbService.selectJhcZbList(jhcZb);
        ExcelUtil<JhcZb> util = new ExcelUtil<JhcZb>(JhcZb.class);
        util.exportExcel(response, list, "进耗存录入总表数据");
    }

    /**
     * 获取进耗存录入总表详细信息
     */
    @PreAuthorize("@ss.hasPermi('jhczb:zb:query')")
    @GetMapping(value = "/{cDate}")
    public AjaxResult getInfo(@PathVariable("cDate") String cDate)
    {
        return AjaxResult.success(jhcZbService.selectJhcZbByCDate(cDate));
    }

    /**
     * 新增进耗存录入总表
     */
    @PreAuthorize("@ss.hasPermi('jhczb:zb:add')")
    @Log(title = "进耗存录入总表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JhcZb jhcZb)
    {
        return toAjax(jhcZbService.insertJhcZb(jhcZb));
    }

    /**
     * 修改进耗存录入总表
     */
    @PreAuthorize("@ss.hasPermi('jhczb:zb:edit')")
    @Log(title = "进耗存录入总表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JhcZb jhcZb)
    {
        return toAjax(jhcZbService.updateJhcZb(jhcZb));
    }

    /**
     * 删除进耗存录入总表
     */
    @PreAuthorize("@ss.hasPermi('jhczb:zb:remove')")
    @Log(title = "进耗存录入总表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cDates}")
    public AjaxResult remove(@PathVariable String[] cDates)
    {
        return toAjax(jhcZbService.deleteJhcZbByCDates(cDates));
    }
    /**
     * 下载生产日报总表列表
     */
    @PreAuthorize("@ss.hasPermi('scrball:all:export')")
    @Log(title = "进耗存总表", businessType = BusinessType.EXPORT)
    @PostMapping("/download")
    public void download(HttpServletResponse response, JhcZb jhcZb) {
        //List<ScrbAll> list = scrbAllService.selectScrbAllList(scrbAll);
        //ExcelUtil<ScrbAll> util = new ExcelUtil<ScrbAll>(ScrbAll.class);
        //util.exportExcel(response, list, "生产日报总表数据");
        jhcZbService.downloadJhcZb(response,jhcZb);
    }
}
